package com.takepoints21.mobile;

import com.facebook.android.SessionStore;
import com.takepoints.android.TPConst;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;

public class Setting extends PreferenceActivity {
	
	private Preference settUsrname = null;
	private Preference settFacebook = null;
	
	@Override
    protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
	    addPreferencesFromResource(R.xml.setting);
	    
	    SharedPreferences sharePref = PreferenceManager.getDefaultSharedPreferences(this);
	    String prefUsrname = sharePref.getString(TPConst.PRF_USRNAME, TPConst.NOT_AVAIL);
	    
	    settUsrname = (Preference)findPreference(TPConst.STT_USRNAME);
	    settUsrname.setSummary(prefUsrname);
	    settUsrname.setOnPreferenceClickListener(new OnPreferenceClickListener(){
	    	public boolean onPreferenceClick(Preference preference){
	    		Intent loginInt = new Intent(preference.getContext(), UserLogin.class);
	    		loginInt.putExtra("pageSrc", "SETTING");
	    		startActivityForResult(loginInt, 0);
				return true;
	    	}
	    });
	    
	    settFacebook = (Preference)findPreference(TPConst.STT_FACEBOOK);
	    String fbName = SessionStore.getName(this);
	    if(fbName != null){
	    	settFacebook.setSummary(fbName);
	    }
	    settFacebook.setOnPreferenceClickListener(new OnPreferenceClickListener(){
	    	public boolean onPreferenceClick(Preference preference){
	    		Intent fbAppsInt = new Intent(preference.getContext(), FacebookApps.class);
	    		startActivityForResult(fbAppsInt, 0);
				return true;
	    	}
	    });
	}
	
}
